package com.gitee.wsl.mathematics.geometry.d2.circle.ext

import com.gitee.wsl.mathematics.coordinate.d2.Coordinate2
import com.gitee.wsl.mathematics.coordinate.polar.ext.polar
import com.gitee.wsl.mathematics.geometry.d2.base.SizeAble2d
import com.gitee.wsl.mathematics.geometry.d2.circle.CircleShape2d
import com.gitee.wsl.mathematics.geometry.d2.circle.EllipseShape2d
import com.gitee.wsl.mathematics.vector.ext.between
import com.gitee.wsl.unit.angle.AngleUnit
import com.gitee.wsl.unit.angle.ext.cos
import com.gitee.wsl.unit.angle.ext.sin

fun<N:Number,V: Coordinate2<N, V>,S: SizeAble2d<N, S>> EllipseShape2d<N, V, S>.projectedPoint(p: Coordinate2<N, *>): V {
    val angle = AngleUnit.between(center, p)
    return center + createPoint2(radius.width * angle.cos(), radius.height * angle.sin())

    //val k = (radius.width * radius.height) / sqrt()
    //return projectPointOntoEllipse(p, center, radius.toVector())
}

fun<N:Number,V: Coordinate2<N, V>> CircleShape2d<N, V>.projectedPoint(p: Coordinate2<N, *>) = polar(center, AngleUnit.between(center, p), radius.toFloat())

